﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Might.Infrastructure.DOM {

    public interface IDomReference {    
        IDomNode Owner { get; }
        IDomNode Reference { get; set; }
        void ClearReference();
    }

    public class DomReference : IDomReference {

        public DomReference() {}

        public DomReference(IDomNode owner) {
            Owner = owner;
        }

        #region IDomReference Members

        public IDomNode Reference {
            get { return reference; }
            set {
                if (value != null && value != reference) {
                    value.SetAsReference(Owner);
                }
                reference = value;
            }
        }

        private IDomNode reference;

        public IDomNode Owner { get; private set; }

        public void ClearReference() {
            if (reference != null) {
                reference.RemoveAsReference(Owner);
            }
        }

        #endregion
    }
    
}
